/*=============================================================================
*
*   Copyright (C) 2020 All rights reserved.
*
*   Filename:		tri2degree.cpp
*
*   Author: Wang Zhecheng - wangzhecheng@yeah.net
*
*   Date: 2020-02-20 21:23
*
*   Last Editors: Wang Zhecheng - wangzhecheng@yeah.net
*
*   Last modified:	2020-08-13 02:57
*
*   Description:
*
=============================================================================*/
/* #define BOOST_TEST_MODULE test_P52 */

#include "../../include/fem.hpp"
#include "../../include/implicit_solver.hpp"
#include "../../include/incremental_load.hpp"
#include "../../include/model/model.hpp"
#include "../../include/solid.hpp"
#include "../../include/static_equation.hpp"
/* #include <boost/test/included/unit_test.hpp> */

LOGGING_REGISTER()

/* BOOST_AUTO_TEST_CASE(test_P52) { */
int main(int argc, char* argv[]) {
  /*  detail, trace, process, info, warning, debug, error }; */
  geoxfem::log::log_init(geoxfem::log::severity_level::error);

  using namespace geoxfem;
  using namespace geoxfem::model;
  using namespace geoxfem::geometry;

  using MethodPolicy   = fem;
  using CouplePolicy   = solid;
  using DimensionType  = plane_strain;
  using EquationPolicy = static_equation;
  using SolvePolicy    = implicit_solver;
  using LoadPolicy     = incremental_load;
  using Model =
    geoxfem::model::Model<MethodPolicy, CouplePolicy, DimensionType,
                          EquationPolicy, SolvePolicy, LoadPolicy, mpl2>;
  using pointt_type = Point<2>;

  /* std::string input_file_name = */
  /*   (boost::unit_test::framework::master_test_suite().argc < 2) */
  /*     ? "test/test_cell/tri2degree.json" */
  /*     : boost::unit_test::framework::master_test_suite().argv[1]; */
  std::string input_file_name =
    argc < 2 ? "test/test_cell/tri2degree.json" : argv[1];

  /*  detail, trace, process, info, warning, debug, error }; */
  geoxfem::log::log_init(geoxfem::log::severity_level::error);

  io::DataParser<io::json> parser;
  parser.read(input_file_name);

  /* io::DataExtractor<Model> extractor; */
  /* extractor.init(parser); */

  io::DataWriter<Model, io::vtu> writer;
  writer.init(parser.getPath(), parser.getFileName());

  /* io::DataPloter                 ploter; */

  Model model;
  /* model.append(extractor); */
  model.append(&writer);

  model.init(parser);
  model.buildProblem();
  model.solveProblem();

  _real area = 0;
  for(auto& cell : shapesIn(*model.getMesh(), 2))
    for(auto& gp : gpsIn(*cell)) {
      area += gp.getWeight();
      /* std::cout << cell->getStdNByGlobal(gp.getCoord()) << std::endl; */
      /* std::cout << ".............." << std::endl; */
    }

  std::cout << area << std::endl;

  pointt_type p0{-2, -2};
  pointt_type p1{2, -2};
  pointt_type p4{0, -1};
  pointt_type p8{0, 0};
  pointt_type p9{0.5, -0.5};
  pointt_type p10{-0.5, -0.5};

  return 0;
}
